<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateInstallmentItemsTable extends Migration
{
    public function up() {
        Schema::create('installment_items', function (Blueprint $table) {
            $table->id();
            //分期 ID
            $table->unsignedBigInteger('installment_id');
            $table->foreign('installment_id')->references('id')->on('installments')->onDelete('cascade');
            //还款顺序编号
            $table->unsignedInteger('sequence');
            //当期本金
            $table->decimal('base');
            //当期手续费
            $table->decimal('fee');
            //当期逾期费
            $table->decimal('fine')->nullable();
            //还款截止日期
            $table->dateTime('due_date');
            //还款日期
            $table->dateTime('paid_at')->nullable();
            //还款支付方式
            $table->string('payment_method')->nullable();
            //还款支付平台订单号
            $table->string('payment_no')->nullable();
            //退款状态
            $table->string('refund_status')->default(\App\Models\InstallmentItem::REFUND_STATUS_PENDING);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('installment_items');
    }
}
